﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

public partial class Notes : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //DateTime MyDate = DateTime.Today;
        if (Context.Request.QueryString["type"] != null)
        {
            bool MyType = (Context.Request.QueryString["type"] == "0");
        };
        if (!Page.IsPostBack)
        {
            cldrDateStart.SelectedDate = DateTime.Now.AddDays(-1);
            cldrDateStart.VisibleDate = DateTime.Now.AddDays(-1);
            cldrDateStop.SelectedDate = DateTime.Now;
            cldrDateStop.VisibleDate = DateTime.Now;
            lbHeader.Text = "Данные за " + cldrDateStart.SelectedDate.Date.ToShortDateString();
        };
        dsNotesJobs.SelectCommand = "SELECT * FROM [NotesJobs] ORDER BY [DateStart]";
        rbtnTableType_SelectedIndexChanged(sender, e);
    }
    protected void rbtnTableType_SelectedIndexChanged(object sender, EventArgs e)
    {
        switch (rbtnTableType.SelectedIndex)
        {
            default: lbHeader.Text = cldrDateStart.SelectedDate.ToShortDateString(); break;
            case 0: { gvNotesJobs.Visible = true; dvNotesJob.Visible = true;
                gvNotesRefuse.Visible = false; dvNotesRefuse.Visible = false;
                gvNotesJobs.DataBind(); 
                lbItog.Text = "Итого работ: " + gvNotesJobs.Rows.Count; } break;
            case 1: { gvNotesJobs.Visible = false; dvNotesJob.Visible = false;
                gvNotesRefuse.Visible = true; dvNotesRefuse.Visible = true;
                gvNotesRefuse.DataBind(); 
                lbItog.Text = "Итого отказов: " + gvNotesRefuse.Rows.Count; ; } break;
        }
    }
    protected void dsNotesJobsDetails_Updated(object sender, SqlDataSourceStatusEventArgs e)
    {
        gvNotesJobs.DataBind();
    }
    protected void dsNotesJobsDetails_Inserted(object sender, SqlDataSourceStatusEventArgs e)
    {
        gvNotesJobs.DataBind();
    }
    protected void ddlTypeQuery_SelectedIndexChanged(object sender, EventArgs e)
    {
        switch (ddlTypeQuery.SelectedIndex)
        {
            case 0: cldrDateStop.Visible = false; 
                Label1.Visible = false; 
                //gvStatsEP.Columns[6].Visible = true;
                //dsStatsHosts.FilterExpression = "dbegin_stat='{0}'";
                break;
            case 1: cldrDateStop.Visible = true; 
                Label1.Visible = true; 
                //gvStatsEP.Columns[6].Visible = false;
                break;
        }
        cldrDateStart_SelectionChanged(sender, e);
    }
    protected void cldrDateStart_SelectionChanged(object sender, EventArgs e)
    {
        lbHeader.ForeColor = System.Drawing.Color.White;
        if (ddlTypeQuery.SelectedIndex == 0)
        {
            lbHeader.Text = "Данные за " + cldrDateStart.SelectedDate.Date.ToShortDateString();
            //cldrDateStop.SelectedDate = cldrDateStart.SelectedDate.Date.AddDays(1);
            cldrDateStop.SelectedDate = cldrDateStart.SelectedDate.Date;
        }
        else
        {
            if (cldrDateStart.SelectedDate.Date > cldrDateStop.SelectedDate.Date)
            {
                lbHeader.Text = "Некорректный диапазон дат. Дата начала должна быть меньше даты конца!";
                lbHeader.ForeColor = System.Drawing.Color.Red;
            }
            else
            {
                lbHeader.Text = "Данные за период с " + cldrDateStart.SelectedDate.Date.ToShortDateString() + " по " + cldrDateStop.SelectedDate.Date.ToShortDateString();
            }

        }
        //gvStatsEP.DataBind();
        //gvStatsHosts.DataBind();

    }
}
